
use crate::vec::*;
use crate::ray::Ray;

pub struct Camera {
    origin: Point3,
    lower_left_corner: Point3,
    horizontal: Vec3,
    vertical: Vec3
}

impl Default for Camera {
    fn default() -> Self {
        let aspect_ration:f32 = 16.0/9.0;
        let viewport_h:f32 = 2.0;
        let viewport_w :f32 = aspect_ration * viewport_h;
        let focal_length :f32 = 1.0;

        let origin = Point3::default();
        let  horizontal = Vec3::new(viewport_w, 0., 0.);
        let vertical = Vec3::new(0., viewport_h, 0.);
        let lower_left_corner = origin - horizontal/2. - vertical/2. - Vec3::new(0., 0., focal_length);

        Self { origin,horizontal,vertical,lower_left_corner }

    }
}

impl Camera {
    pub fn get_ray(&self, u: f32, v:f32) -> Ray {
        Ray::new(self.origin, self.lower_left_corner+ u * self.horizontal + v* self.vertical)
    }
}
